package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.lvlian.dto.LhsTricycleDto;
import com.ruoyi.lvlian.vo.SimpleSysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.LhsTricycleMapper;
import com.ruoyi.lvlian.domain.LhsTricycle;
import com.ruoyi.lvlian.service.ILhsTricycleService;

/**
 * 商户三轮车司机信息Service业务层处理
 *
 * @author liyuxi
 * @date 2025-10-09
 */
@Service
public class LhsTricycleServiceImpl implements ILhsTricycleService {
    @Autowired
    private LhsTricycleMapper lhsTricycleMapper;

    /**
     * 查询商户三轮车司机信息
     *
     * @param id 商户三轮车司机信息主键
     * @return 商户三轮车司机信息
     */
    @Override
    public LhsTricycle selectLhsTricycleById(String id) {
        return lhsTricycleMapper.selectLhsTricycleById(id);
    }

    /**
     * 查询商户三轮车司机信息列表
     *
     * @param lhsTricycle 商户三轮车司机信息
     * @return 商户三轮车司机信息
     */
    @Override
    public List<SimpleSysUser> selectLhsTricycleList(LhsTricycleDto lhsTricycle) {
        List<SimpleSysUser> SimpleSysUsers = lhsTricycleMapper.selectLhsTricycleList(lhsTricycle);
  /*      for(SimpleSysUser po:SimpleSysUsers ){
            if(StringUtils.isEmpty(po.getName() )){
                po.setName( po.getSysUser().getNickName());
            }
        }*/
        return SimpleSysUsers;
    }

    /**
     * 新增商户三轮车司机信息
     *
     * @param lhsTricycle 商户三轮车司机信息
     * @return 结果
     */
    @Override
    public int insertLhsTricycle(LhsTricycle lhsTricycle) {
        lhsTricycle.setDataSource("收回莱小程序");
        lhsTricycle.setDataStatus("待审批");
        lhsTricycle.setId(MD5Utils.md5(lhsTricycle.getLicenseNo() + lhsTricycle.getPhoneNo() + lhsTricycle.getDataSource()));

        return lhsTricycleMapper.insertLhsTricycle(lhsTricycle);
    }

    /**
     * 修改商户三轮车司机信息
     *
     * @param lhsTricycle 商户三轮车司机信息
     * @return 结果
     */
    @Override
    public int updateLhsTricycle(LhsTricycle lhsTricycle) {
        lhsTricycle.setCreateUser(SecurityUtils.getUsername());
        lhsTricycle.setCreateDate(DateUtils.getCurrentTime());

        int updateResult =  lhsTricycleMapper.updateLhsTricycle(lhsTricycle);
        if (0 == updateResult) {
            updateResult = insertLhsTricycle(lhsTricycle);
        }

        return updateResult;

    }

    /**
     * 批量删除商户三轮车司机信息
     *
     * @param ids 需要删除的商户三轮车司机信息主键
     * @return 结果
     */
    @Override
    public int deleteLhsTricycleByIds(String[] ids) {
        return lhsTricycleMapper.deleteLhsTricycleByIds(ids);
    }

    /**
     * 删除商户三轮车司机信息信息
     *
     * @param id 商户三轮车司机信息主键
     * @return 结果
     */
    @Override
    public int deleteLhsTricycleById(String id) {
        return lhsTricycleMapper.deleteLhsTricycleById(id);
    }

    @Override
    public SimpleSysUser getInfoByPhone(String phone, String dataSource) {
        return lhsTricycleMapper.getInfoByPhone(phone ,dataSource );
    }
}
